% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/take-draws_poststrat.R
\name{pivot_celldraws_longer}
\alias{pivot_celldraws_longer}
\title{Take output from brms prediction and turn to tidy form}
\usage{
pivot_celldraws_longer(mod_draws, data_strat, yhat_name = "pred_n_yes")
}
\arguments{
\item{mod_draws}{Output from \code{posterior_*pred}, which is of dimension
\code{Iter} (in rows) by \code{Cells} (in columns)}

\item{data_strat}{Covariates to append to. The number of rows should be
the number of \code{Cells}}

\item{yhat_name}{The name of the value for the predicted outcome.}
}
\value{
A tidy long dataset with \code{Iter} x \code{Cells} rows. Columns
will include the columns of \code{data_strat}, the iteration and cell ID, and
the predicted value for that cell at that iteration.
}
\description{
Take output from brms prediction and turn to tidy form
}
\examples{
library(dplyr)
library(brms)

pred_df <- rename(acs_GA, n_response = count) # match variables with model call
posterior_draws <- posterior_epred(object = fit_GA,  # stanfit
                                   newdata = pred_df)

# output is matrix, not tidy form
class(posterior_draws)
dim(posterior_draws)

# tidy out
out <- pivot_celldraws_longer(mod_draws = posterior_draws,
                              data_strat = pred_df,
                              yhat_name = "pred_n_yes")

dim(out)
select(out, cd, n_response, cell, iter, pred_n_yes)


}
